package dao.impl;


import dao.BaseDao.BaseDao;
import javabean.Food;
import javabean.FoodCategory;

import java.util.List;

public class AddCartDaoImpl extends BaseDao implements AddCartDao {

    @Override
    //添加菜品
    public int addCart(Food food) {
        String sql = "insert into t_food(`id`,`name`,`image`,`cpp`,`ifPreferential`,`preferentialPrice`,`ifOnSale`,`ifRecommend`,`introduction`,`categoryId`,`level`) values(?,?,?,?,?,?,?,?,?,?,?)";

        return update(sql,food.getId(),food.getName(),food.getImage(),food.getCpp(),food.getIfPreferential(),food.getPreferentialPrice(),food.getIfOnSale(),food.getIfRecommend(),food.getIntroduction(),food.getCategoryId(),food.getLevel());
    }

    //根据id查找菜品对象
    @Override
    public Food queryFoodById(Integer id) {
        String sql = "select `id`,`name`,`image`,`cpp`,`ifPreferential`,`preferentialPrice`,`ifOnSale`,`ifRecommend`,`introduction`,`categoryId`,`level` from t_food where id = ?";

        return queryForOne(Food.class,sql,id);
    }

    //查找全部菜品对象
    @Override
    public List<Food> queryFoods() {
        String sql= "select `id`,`name`,`image`,`cpp`,`ifPreferential`,`preferentialPrice`,`ifOnSale`,`ifRecommend`,`introduction`,`categoryId`,`level` from t_food";
        return queryForList(Food.class,sql);
    }

    //添加菜系
    @Override
    public int addCategory(FoodCategory foodCategory) {
        String sql = "insert into t_foodcategory(`id`,`name`) values(?,?)";
        return update(sql,foodCategory.getId(),foodCategory.getName());
    }

    //根据id查找菜系
    @Override
    public FoodCategory queryFoodCategoryById(Integer id) {
        String sql = "select `id`,`name` from t_foodcategory where id = ?";
        return queryForOne(FoodCategory.class,sql,id);
    }

    //查找全部菜系
    @Override
    public List<FoodCategory> queryFoodCategorys() {
        String sql = "select `id`,`name` from t_foodcategory";
        return queryForList(FoodCategory.class,sql);
    }

    
}
